﻿using PureMVC.Interfaces;
using PureMVC.Patterns;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HitMediator : Mediator
{

    public new const string NAME = "HitMediator";
    private HitProxy hitProxy;

    public HitMediator(HitView hitView) : base(NAME, hitView)
    {
    }
    public HitView HitView
    {
        get { return (HitView)base.ViewComponent; }
    }
    public override void OnRegister()
    {
        base.OnRegister();

        HitView.submit += () => { SendNotification(HitSystemEvent.StartCommand, null, "AddScore"); };

        hitProxy = Facade.RetrieveProxy(HitProxy.NAME) as HitProxy;
        if (null == hitProxy)
            throw new Exception(HitProxy.NAME + "is null!");
        HitView.UpdateItem();
    }

    public override IList<string> ListNotificationInterests()
    {
        IList<string> notifications = new List<string>();
        notifications.Add(HitSystemEvent.GameBegin);
        notifications.Add(HitSystemEvent.GameOver);
        return notifications;
    }
    public override void HandleNotification(INotification notification)
    {
        switch (notification.Name)
        {
            case HitSystemEvent.GameBegin:
                Debug.Log("进入Handle开始游戏");
                HitView.Begin();
                break;
            case HitSystemEvent.GameOver:
                HitView.Over();
                break;
        }
    }
}
